package com.ftj.service.impl;

import com.ftj.mapper.CourseOrderMapper;
import com.ftj.pojo.CourseOrder;
import com.ftj.pojo.MonthIncome;
import com.ftj.service.CourseOrderService;
import com.ftj.vo.DataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 21seu.ftj
 */
@Service
public class CourseOrderServiceImpl implements CourseOrderService {

    @Autowired
    private CourseOrderMapper courseOrderMapper;

    /**
     * @param condition
     * @param page
     * @param pageSize
     * @return
     */
    @Override
    public DataVO<CourseOrder> findDataVO(CourseOrder condition, int page, int pageSize) {
        DataVO<CourseOrder> dataVO = new DataVO<>();
        dataVO.setCode(0);
        dataVO.setMsg("");
        //查询参数
        Map<String, Object> params = new HashMap<>();
        params.put("startPage", (page - 1) * pageSize);
        params.put("size", pageSize);
        params.put("condition", condition);
        dataVO.setCount(courseOrderMapper.findCountByMap(params));
        //获取查询的数据
        List<CourseOrder> list = courseOrderMapper.findListByMap(params);
        dataVO.setData(list);
        return dataVO;
    }

    @Override
    public boolean save(CourseOrder courseOrder) {
        return courseOrderMapper.save(courseOrder);
    }

    @Override
    public CourseOrder findByOrderId(String order_id) {
        return courseOrderMapper.findByOrderId(order_id);
    }

    @Override
    public boolean delOrderByOrderId(String order_id) {
        return courseOrderMapper.delOrderByOrderId(order_id);
    }

    @Override
    public boolean updateOrderById(String order_id, CourseOrder courseOrder) {
        return courseOrderMapper.updateOrderById(order_id, courseOrder);
    }

    @Override
    public List<MonthIncome> getMonthIncomes() {
        return courseOrderMapper.getMonthIncomes();
    }
}
